<!DOCTYPE html><html><head><meta charset="utf-8"><title>rocketmq中broker启动同步topic到namesrv过程 | Lehoon</title><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta name="description" content="rocketmq中broker启动同步topic到namesrv过程."><meta property="og:type" content="article"><meta property="og:title" content="rocketmq中broker启动同步topic到namesrv过程"><meta property="og:url" content="http://blog.lehoon.cn/rocketmq/2016/11/13/rocketmq-broker-synctopic2namesrv.html"><meta property="og:site_name" content="Lehoon"><meta property="og:description" content="rocketmq中broker启动同步topic到namesrv过程."><meta property="og:updated_time" content="2016-11-24T07:52:12.364Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="rocketmq中broker启动同步topic到namesrv过程"><meta name="twitter:description" content="rocketmq中broker启动同步topic到namesrv过程."><link rel="alternative" href="/rss.xml" title="Lehoon" type="application/atom+xml"><link rel="icon" href="/favicon.ico"><link rel="stylesheet" href="/css/style.css"><link rel="stylesheet" href="http://static.lehoon.cn/font-awesome.min.css"><link rel="apple-touch-icon" href="/img/apple-touch-icon.png"><link rel="stylesheet" href="http://static.lehoon.cn/fancybox/jquery.fancybox.css"><script src="http://static.lehoon.cn/js/pace.js"></script><link href="/css/pace/pace-theme-flash.css" rel="stylesheet"><script>var yiliaConfig={rootUrl:"/",fancybox:!0,animate:!1,isHome:!1,isPost:!0,isArchive:!1,isTag:!1,isCategory:!1,open_in_new:!1}</script></head><body><div id="container"><div class="left-col"><div class="overlay"></div><div class="intrude-less"><header id="header" class="inner"><hgroup><h1 class="header-author"><a href="/" title="Hi Lehoon">lehoon</a></h1></hgroup><div id="switch-area" class="switch-area"><div class="switch-wrap"><section class="switch-part switch-part1"><nav class="header-menu"><ul><li><a href="/">主页</a></li><li><a href="/archives">文章</a></li><li><a href="/projects">项目</a></li><li><a href="/categories/backend">后端</a></li><li><a href="/categories/frontend">前端</a></li><li><a href="/categories/orther">其他</a></li><li><a href="/polymerization">聚合</a></li><li><a href="/about">关于</a></li></ul></nav><nav class="header-nav"><ul class="social"><a class="fl mail" target="_blank" href="mailto:lehoon@lehoon.com" title="mail">mail</a> <a class="fl github" target="_blank" href="https://github.com/lehoon" title="github">github</a> <a class="fl weibo" target="_blank" href="http://weibo.com/lehoons" title="weibo">weibo</a> <a class="fl rss" target="_blank" href="/rss.xml" title="rss">rss</a></ul></nav></section><section class="switch-part switch-part3"><div id="js-aboutme">热爱生活，享受生活。</div></section></div></div></header></div></div><div class="mid-col"><nav id="mobile-nav"><div class="overlay"><div class="slider-trigger"></div><h1 class="header-author js-mobile-header hide"><a href="/" title="Me">lehoon</a></h1></div><div class="intrude-less"><header id="header" class="inner"><hgroup><h1 class="header-author"><a href="/" title="Me">lehoon</a></h1></hgroup><nav class="header-menu"><ul><li><a href="/">主页</a></li><li><a href="/archives">文章</a></li><li><a href="/projects">项目</a></li><li><a href="/categories/backend">后端</a></li><li><a href="/categories/frontend">前端</a></li><li><a href="/categories/orther">其他</a></li><li><a href="/polymerization">聚合</a></li><li><a href="/about">关于</a></li><div class="clearfix"></div></ul></nav><nav class="header-nav"><div class="social"><a class="mail" target="_blank" href="mailto:lehoon@lehoon.com" title="mail">mail</a> <a class="github" target="_blank" href="https://github.com/lehoon" title="github">github</a> <a class="weibo" target="_blank" href="http://weibo.com/lehoons" title="weibo">weibo</a> <a class="rss" target="_blank" href="/rss.xml" title="rss">rss</a></div></nav></header></div></nav><div class="body-wrap"><article id="post-rocketmq-broker-synctopic2namesrv" class="article article-type-post" itemscope itemprop="blogPost"><div class="article-meta"><a href="/rocketmq/2016/11/13/rocketmq-broker-synctopic2namesrv.html" class="article-date"><time datetime="2016-11-13T12:43:31.000Z" itemprop="datePublished">2016-11-13</time></a></div><div class="article-inner"><input type="hidden" class="isFancy"><header class="article-header"><h1 class="article-title" itemprop="name">rocketmq中broker启动同步topic到namesrv过程</h1></header><div class="article-info article-info-post"><div class="article-category tagcloud"><a class="article-category-link" href="/categories/rocketmq/">rocketmq</a></div><div class="article-tag tagcloud"><ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/broker/">broker</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/rocketmq/">rocketmq</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/topic/">topic</a></li></ul></div><div class="clearfix"></div></div><div class="article-entry" itemprop="articleBody"><p>rocketmq中broker启动同步topic到namesrv过程.<br><a id="more"></a></p><h2 id="broker端"><a href="#broker端" class="headerlink" title="broker端"></a>broker端</h2><h3 id="topic的获取"><a href="#topic的获取" class="headerlink" title="topic的获取"></a>topic的获取</h3><p>broker启动会初始化一些系统或者用户自建的topic，在TopicConfigManager中实现，构造TopicConfigManager的时候初始化系统内置的topic，代码如下：<br></p><figure class="highlight arduino"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> TopicConfigManager(BrokerController brokerController) &#123;</div><div class="line">    <span class="keyword">this</span>.brokerController = brokerController;</div><div class="line">    &#123;</div><div class="line">        <span class="comment">// MixAll.SELF_TEST_TOPIC</span></div><div class="line">        <span class="keyword">String</span> topic = MixAll.SELF_TEST_TOPIC;</div><div class="line">        TopicConfig topicConfig = <span class="keyword">new</span> TopicConfig(topic);</div><div class="line">        <span class="keyword">this</span>.systemTopicList.add(topic);</div><div class="line">        topicConfig.setReadQueueNums(<span class="number">1</span>);</div><div class="line">        topicConfig.setWriteQueueNums(<span class="number">1</span>);</div><div class="line">        <span class="keyword">this</span>.topicConfigTable.<span class="built_in">put</span>(topicConfig.getTopicName(), topicConfig);</div><div class="line">    &#125;</div><div class="line">    &#123;</div><div class="line">        <span class="comment">// MixAll.DEFAULT_TOPIC</span></div><div class="line">        <span class="built_in">if</span> (<span class="keyword">this</span>.brokerController.getBrokerConfig().isAutoCreateTopicEnable()) &#123;</div><div class="line">            <span class="keyword">String</span> topic = MixAll.DEFAULT_TOPIC;</div><div class="line">            TopicConfig topicConfig = <span class="keyword">new</span> TopicConfig(topic);</div><div class="line">            <span class="keyword">this</span>.systemTopicList.add(topic);</div><div class="line">            topicConfig.setReadQueueNums(<span class="keyword">this</span>.brokerController.getBrokerConfig()</div><div class="line">                    .getDefaultTopicQueueNums());</div><div class="line">            topicConfig.setWriteQueueNums(<span class="keyword">this</span>.brokerController.getBrokerConfig()</div><div class="line">                    .getDefaultTopicQueueNums());</div><div class="line">            <span class="keyword">int</span> perm = PermName.PERM_INHERIT | PermName.PERM_READ | PermName.PERM_WRITE;</div><div class="line">            topicConfig.setPerm(perm);</div><div class="line">            <span class="keyword">this</span>.topicConfigTable.<span class="built_in">put</span>(topicConfig.getTopicName(), topicConfig);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    &#123;</div><div class="line">        <span class="comment">// MixAll.BENCHMARK_TOPIC</span></div><div class="line">        <span class="keyword">String</span> topic = MixAll.BENCHMARK_TOPIC;</div><div class="line">        TopicConfig topicConfig = <span class="keyword">new</span> TopicConfig(topic);</div><div class="line">        <span class="keyword">this</span>.systemTopicList.add(topic);</div><div class="line">        topicConfig.setReadQueueNums(<span class="number">1024</span>);</div><div class="line">        topicConfig.setWriteQueueNums(<span class="number">1024</span>);</div><div class="line">        <span class="keyword">this</span>.topicConfigTable.<span class="built_in">put</span>(topicConfig.getTopicName(), topicConfig);</div><div class="line">    &#125;</div><div class="line">    &#123;</div><div class="line"></div><div class="line">        <span class="keyword">String</span> topic = <span class="keyword">this</span>.brokerController.getBrokerConfig().getBrokerClusterName();</div><div class="line">        TopicConfig topicConfig = <span class="keyword">new</span> TopicConfig(topic);</div><div class="line">        <span class="keyword">this</span>.systemTopicList.add(topic);</div><div class="line">        <span class="keyword">int</span> perm = PermName.PERM_INHERIT;</div><div class="line">        <span class="built_in">if</span> (<span class="keyword">this</span>.brokerController.getBrokerConfig().isClusterTopicEnable()) &#123;</div><div class="line">            perm |= PermName.PERM_READ | PermName.PERM_WRITE;</div><div class="line">        &#125;</div><div class="line">        topicConfig.setPerm(perm);</div><div class="line">        <span class="keyword">this</span>.topicConfigTable.<span class="built_in">put</span>(topicConfig.getTopicName(), topicConfig);</div><div class="line">    &#125;</div><div class="line">    &#123;</div><div class="line"></div><div class="line">        <span class="keyword">String</span> topic = <span class="keyword">this</span>.brokerController.getBrokerConfig().getBrokerName();</div><div class="line">        TopicConfig topicConfig = <span class="keyword">new</span> TopicConfig(topic);</div><div class="line">        <span class="keyword">this</span>.systemTopicList.add(topic);</div><div class="line">        <span class="keyword">int</span> perm = PermName.PERM_INHERIT;</div><div class="line">        <span class="built_in">if</span> (<span class="keyword">this</span>.brokerController.getBrokerConfig().isBrokerTopicEnable()) &#123;</div><div class="line">            perm |= PermName.PERM_READ | PermName.PERM_WRITE;</div><div class="line">        &#125;</div><div class="line">        topicConfig.setReadQueueNums(<span class="number">1</span>);</div><div class="line">        topicConfig.setWriteQueueNums(<span class="number">1</span>);</div><div class="line">        topicConfig.setPerm(perm);</div><div class="line">        <span class="keyword">this</span>.topicConfigTable.<span class="built_in">put</span>(topicConfig.getTopicName(), topicConfig);</div><div class="line">    &#125;</div><div class="line">    &#123;</div><div class="line">        <span class="comment">// MixAll.OFFSET_MOVED_EVENT</span></div><div class="line">        <span class="keyword">String</span> topic = MixAll.OFFSET_MOVED_EVENT;</div><div class="line">        TopicConfig topicConfig = <span class="keyword">new</span> TopicConfig(topic);</div><div class="line">        <span class="keyword">this</span>.systemTopicList.add(topic);</div><div class="line">        topicConfig.setReadQueueNums(<span class="number">1</span>);</div><div class="line">        topicConfig.setWriteQueueNums(<span class="number">1</span>);</div><div class="line">        <span class="keyword">this</span>.topicConfigTable.<span class="built_in">put</span>(topicConfig.getTopicName(), topicConfig);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure><p></p><p>用户自建的topic会通过TopicConfigManager的父类ConfigManager.load方法把本地存储的${user.home}/store/config/topic.json 加载出来，然后通过decode方法把json的数据转换出来保存到topicConfigTable表里面去。</p><p>这样topic数据就获取到了。<br>当然第一次运行broker的时候，只有系统内建的topic。</p><h3 id="同步到namesrv"><a href="#同步到namesrv" class="headerlink" title="同步到namesrv"></a>同步到namesrv</h3><p>启动broker服务中，通过调用BrokerController.start()方法启动broker。<br></p><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 启动broker服务 </div><div class="line"> */</div><div class="line"><span class="keyword">public</span> void start() throws Exception </div><div class="line">&#123;</div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.messageStore != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.messageStore.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.remotingServer != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.remotingServer.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.fastRemotingServer != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.fastRemotingServer.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.brokerOuterAPI != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.brokerOuterAPI.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.pullRequestHoldService != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.pullRequestHoldService.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.clientHousekeepingService != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.clientHousekeepingService.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.filterServerManager != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.filterServerManager.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 注册broker到namesrv上去</div><div class="line">     */</div><div class="line">    <span class="keyword">this</span>.registerBrokerAll(<span class="literal">true</span>, <span class="literal">false</span>);</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 定时注册broker到namesrv上去</div><div class="line">     * 启动10秒后运行</div><div class="line">     * 每隔30秒定时注册broker到namesrv上去</div><div class="line">     */</div><div class="line">    <span class="keyword">this</span>.scheduledExecutorService.scheduleAtFixedRate(new Runnable() &#123;</div><div class="line"></div><div class="line">        <span class="meta">@Override</span></div><div class="line">        <span class="keyword">public</span> void run() &#123;</div><div class="line">            <span class="keyword">try</span> &#123;</div><div class="line">                BrokerController.<span class="keyword">this</span>.registerBrokerAll(<span class="literal">true</span>, <span class="literal">false</span>);</div><div class="line">            &#125; <span class="keyword">catch</span> (Throwable e) &#123;</div><div class="line">                log.error(<span class="string">"registerBrokerAll Exception"</span>, e);</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">    &#125;, <span class="number">1000</span> * <span class="number">10</span>, <span class="number">1000</span> * <span class="number">30</span>, TimeUnit.MILLISECONDS);</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.brokerStatsManager != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.brokerStatsManager.start();</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span>.brokerFastFailure != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">this</span>.brokerFastFailure.start();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure><p></p><p>启动过程中调用了registerBrokerAll方法，注册broker到namesrv上去。<br>然后又启动一个定时注册任务来保证broker在namesrv上的可用性。<br>registerBrokerAll定义如下：<br></p><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> synchronized void registerBrokerAll(<span class="keyword">final</span> boolean checkOrderConfig, boolean oneway) </div><div class="line">&#123;</div><div class="line">    <span class="comment">/**</span></div><div class="line">     * topic配置序列化包装对象</div><div class="line">     */</div><div class="line">    TopicConfigSerializeWrapper topicConfigWrapper = <span class="keyword">this</span>.getTopicConfigManager().buildTopicConfigSerializeWrapper();</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 如果broker没有读写权限</div><div class="line">     */</div><div class="line">    <span class="keyword">if</span> (!PermName.isWriteable(<span class="keyword">this</span>.getBrokerConfig().getBrokerPermission())</div><div class="line">            || !PermName.isReadable(<span class="keyword">this</span>.getBrokerConfig().getBrokerPermission())) </div><div class="line">    &#123;</div><div class="line">        ConcurrentHashMap&lt;String, TopicConfig&gt; topicConfigTable = new ConcurrentHashMap&lt;String, TopicConfig&gt;();</div><div class="line">        <span class="keyword">for</span> (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) &#123;</div><div class="line">            TopicConfig tmp =</div><div class="line">                    new TopicConfig(topicConfig.getTopicName(),         <span class="comment">//topic名称</span></div><div class="line">                            topicConfig.getReadQueueNums(),             <span class="comment">//读队列大小</span></div><div class="line">                            topicConfig.getWriteQueueNums(),            <span class="comment">//写队列大小</span></div><div class="line">                            <span class="keyword">this</span>.brokerConfig.getBrokerPermission());   <span class="comment">//权限</span></div><div class="line">            topicConfigTable.put(topicConfig.getTopicName(), tmp);</div><div class="line">        &#125;</div><div class="line">        topicConfigWrapper.setTopicConfigTable(topicConfigTable);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">//注册broker到namesrv</span></div><div class="line">    RegisterBrokerResult registerBrokerResult = <span class="keyword">this</span>.brokerOuterAPI.registerBrokerAll(<span class="comment">//</span></div><div class="line">            <span class="keyword">this</span>.brokerConfig.getBrokerClusterName(), <span class="comment">//broker配置的集群名称</span></div><div class="line">            <span class="keyword">this</span>.getBrokerAddr(), <span class="comment">//   broker地址</span></div><div class="line">            <span class="keyword">this</span>.brokerConfig.getBrokerName(), <span class="comment">// broker名称</span></div><div class="line">            <span class="keyword">this</span>.brokerConfig.getBrokerId(), <span class="comment">// brokerid</span></div><div class="line">            <span class="keyword">this</span>.getHAServerAddr(), <span class="comment">// ha的服务地址</span></div><div class="line">            topicConfigWrapper,<span class="comment">// topic配置文件</span></div><div class="line">            <span class="keyword">this</span>.filterServerManager.buildNewFilterServerList(),<span class="comment">//过滤服务列表</span></div><div class="line">            oneway,<span class="comment">//是否选择oneway方式  false</span></div><div class="line">            <span class="keyword">this</span>.brokerConfig.getRegisterBrokerTimeoutMills()); <span class="comment">//超时时间</span></div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">    * 忽略下面</div><div class="line">    */</div><div class="line">    <span class="keyword">if</span> (registerBrokerResult != <span class="literal">null</span>) &#123;</div><div class="line">        <span class="keyword">if</span> (<span class="keyword">this</span>.updateMasterHAServerAddrPeriodically &amp;&amp; registerBrokerResult.getHaServerAddr() != <span class="literal">null</span>) &#123;</div><div class="line">            <span class="keyword">this</span>.messageStore.updateHaMasterAddress(registerBrokerResult.getHaServerAddr());</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="keyword">this</span>.slaveSynchronize.setMasterAddr(registerBrokerResult.getMasterAddr());</div><div class="line"></div><div class="line">        <span class="keyword">if</span> (checkOrderConfig) &#123;</div><div class="line">            <span class="keyword">this</span>.getTopicConfigManager().updateOrderTopicConfig(registerBrokerResult.getKvTable());</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure><p></p><p>brokerOuterAPI.registerBrokerAll定义如下：<br></p><figure class="highlight zephir"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * @描述: 注册broker到namesrv上去 </div><div class="line"> * @修改内容</div><div class="line"> * @参数：<span class="doctag">@param</span> clusterName</div><div class="line"> * @参数：<span class="doctag">@param</span> brokerAddr</div><div class="line"> * @参数：<span class="doctag">@param</span> brokerName</div><div class="line"> * @参数：<span class="doctag">@param</span> brokerId</div><div class="line"> * @参数：<span class="doctag">@param</span> haServerAddr</div><div class="line"> * @参数：<span class="doctag">@param</span> topicConfigWrapper</div><div class="line"> * @参数：<span class="doctag">@param</span> filterServerList</div><div class="line"> * @参数：<span class="doctag">@param</span> oneway</div><div class="line"> * @参数：<span class="doctag">@param</span> timeoutMills</div><div class="line"> * @参数：<span class="doctag">@return</span>     </div><div class="line"> * <span class="doctag">@throws</span></div><div class="line"> */</div><div class="line"><span class="keyword">public</span> RegisterBrokerResult registerBrokerAll(<span class="comment">//</span></div><div class="line">                                              <span class="keyword">final</span> String clusterName, <span class="comment">// 1 集群名称</span></div><div class="line">                                              <span class="keyword">final</span> String brokerAddr, <span class="comment">// 2 broker地址</span></div><div class="line">                                              <span class="keyword">final</span> String brokerName, <span class="comment">// 3 broker名称</span></div><div class="line">                                              <span class="keyword">final</span> <span class="keyword">long</span> brokerId, <span class="comment">// 4   brokerid</span></div><div class="line">                                              <span class="keyword">final</span> String haServerAddr, <span class="comment">// 5 haServerAddr</span></div><div class="line">                                              <span class="keyword">final</span> TopicConfigSerializeWrapper topicConfigWrapper, <span class="comment">// 6 topic配置</span></div><div class="line">                                              <span class="keyword">final</span> <span class="keyword">List</span>&lt;String&gt; filterServerList, <span class="comment">// 7 过滤server</span></div><div class="line">                                              <span class="keyword">final</span> <span class="keyword">boolean</span> oneway,<span class="comment">// 8  是否oneway方式</span></div><div class="line">                                              <span class="keyword">final</span> <span class="keyword">int</span> timeoutMills<span class="comment">// 9  超时事件</span></div><div class="line">) &#123;</div><div class="line">    RegisterBrokerResult registerBrokerResult = <span class="keyword">null</span>;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 获得nameserv地址集合</div><div class="line">     */</div><div class="line">    <span class="keyword">List</span>&lt;String&gt; nameServerAddressList = this.remotingClient.getNameServerAddressList();</div><div class="line">    </div><div class="line">    <span class="keyword">if</span> (nameServerAddressList != <span class="keyword">null</span>) &#123;</div><div class="line">        <span class="keyword">for</span> (String namesrvAddr : nameServerAddressList) &#123;</div><div class="line">            <span class="keyword">try</span> &#123;</div><div class="line">                <span class="comment">/**</span></div><div class="line">                 * 发送注册broker的请求消息到namesrv上去</div><div class="line">                 */</div><div class="line">                RegisterBrokerResult result = this.registerBroker(namesrvAddr, clusterName, brokerAddr, brokerName, brokerId,</div><div class="line">                        haServerAddr, topicConfigWrapper, filterServerList, oneway, timeoutMills);</div><div class="line">                <span class="keyword">if</span> (result != <span class="keyword">null</span>) &#123;</div><div class="line">                    registerBrokerResult = result;</div><div class="line">                &#125;</div><div class="line"></div><div class="line">                log.info(<span class="string">"register broker to name server &#123;&#125; OK"</span>, namesrvAddr);</div><div class="line">            &#125; <span class="keyword">catch</span> (<span class="keyword">Exception</span> e) &#123;</div><div class="line">                log.warn(<span class="string">"registerBroker Exception, "</span> + namesrvAddr, e);</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">return</span> registerBrokerResult;</div><div class="line">&#125;</div></pre></td></tr></table></figure><p></p><p>真实注册逻辑在registerBroker实现方式如：<br></p><figure class="highlight zephir"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * @描述:  注册broker的到namesrv上去</div><div class="line"> * @修改内容</div><div class="line"> * @参数：<span class="doctag">@param</span> namesrvAddr   namesrv地址</div><div class="line"> * @参数：<span class="doctag">@param</span> clusterName   集群名称</div><div class="line"> * @参数：<span class="doctag">@param</span> brokerAddr    broker地址</div><div class="line"> * @参数：<span class="doctag">@param</span> brokerName    broker名称</div><div class="line"> * @参数：<span class="doctag">@param</span> brokerId      brokerid</div><div class="line"> * @参数：<span class="doctag">@param</span> haServerAddr  haServer</div><div class="line"> * @参数：<span class="doctag">@param</span> topicConfigWrapper  topic配置</div><div class="line"> * @参数：<span class="doctag">@param</span> filterServerList    过滤服务器</div><div class="line"> * @参数：<span class="doctag">@param</span> oneway              oneway方式</div><div class="line"> * @参数：<span class="doctag">@param</span> timeoutMills        超时时间</div><div class="line"> * @参数：<span class="doctag">@return</span>  RegisterBrokerResult  结果</div><div class="line"> * @参数：<span class="doctag">@throws</span> RemotingCommandException</div><div class="line"> * @参数：<span class="doctag">@throws</span> MQBrokerException</div><div class="line"> * @参数：<span class="doctag">@throws</span> RemotingConnectException</div><div class="line"> * @参数：<span class="doctag">@throws</span> RemotingSendRequestException</div><div class="line"> * @参数：<span class="doctag">@throws</span> RemotingTimeoutException</div><div class="line"> * @参数：<span class="doctag">@throws</span> InterruptedException     </div><div class="line"> * <span class="doctag">@throws</span></div><div class="line"> */</div><div class="line"><span class="keyword">private</span> RegisterBrokerResult registerBroker(<span class="comment">//</span></div><div class="line">                                            <span class="keyword">final</span> String namesrvAddr, <span class="comment">//</span></div><div class="line">                                            <span class="keyword">final</span> String clusterName, <span class="comment">// 1</span></div><div class="line">                                            <span class="keyword">final</span> String brokerAddr, <span class="comment">// 2</span></div><div class="line">                                            <span class="keyword">final</span> String brokerName, <span class="comment">// 3</span></div><div class="line">                                            <span class="keyword">final</span> <span class="keyword">long</span> brokerId, <span class="comment">// 4</span></div><div class="line">                                            <span class="keyword">final</span> String haServerAddr, <span class="comment">// 5</span></div><div class="line">                                            <span class="keyword">final</span> TopicConfigSerializeWrapper topicConfigWrapper, <span class="comment">// 6</span></div><div class="line">                                            <span class="keyword">final</span> <span class="keyword">List</span>&lt;String&gt; filterServerList, <span class="comment">// 7</span></div><div class="line">                                            <span class="keyword">final</span> <span class="keyword">boolean</span> oneway,<span class="comment">// 8</span></div><div class="line">                                            <span class="keyword">final</span> <span class="keyword">int</span> timeoutMills<span class="comment">// 9</span></div><div class="line">) throws RemotingCommandException, MQBrokerException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException,</div><div class="line">        InterruptedException </div><div class="line">&#123;</div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 注册broker请求的消息头</div><div class="line">     * 设置broker的属性</div><div class="line">     */</div><div class="line">    RegisterBrokerRequestHeader requestHeader = <span class="keyword">new</span> RegisterBrokerRequestHeader();</div><div class="line">    requestHeader.setBrokerAddr(brokerAddr);</div><div class="line">    requestHeader.setBrokerId(brokerId);</div><div class="line">    requestHeader.setBrokerName(brokerName);</div><div class="line">    requestHeader.setClusterName(clusterName);</div><div class="line">    requestHeader.setHaServerAddr(haServerAddr);</div><div class="line">    </div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 创建请求对象</div><div class="line">     */</div><div class="line">    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.REGISTER_BROKER, requestHeader);</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 消息体</div><div class="line">     */</div><div class="line">    RegisterBrokerBody requestBody = <span class="keyword">new</span> RegisterBrokerBody();</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 把broker上的topic信息加到消息体中去</div><div class="line">     */</div><div class="line">    requestBody.setTopicConfigSerializeWrapper(topicConfigWrapper);</div><div class="line">    requestBody.setFilterServerList(filterServerList);</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">    * 把序列化的请求消息体附加到请求对象上去</div><div class="line">    */</div><div class="line">    request.setBody(requestBody.encode());</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 如果是oneway方式发送</div><div class="line">     */</div><div class="line">    <span class="keyword">if</span> (oneway) &#123;</div><div class="line">        <span class="keyword">try</span> &#123;</div><div class="line">            this.remotingClient.invokeOneway(namesrvAddr, request, timeoutMills);</div><div class="line">        &#125; <span class="keyword">catch</span> (RemotingTooMuchRequestException e) &#123;</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="comment">/**</span></div><div class="line">        * 直接返回</div><div class="line">        */</div><div class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 同步发送调用</div><div class="line">     */</div><div class="line">    RemotingCommand response = this.remotingClient.invokeSync(namesrvAddr, request, timeoutMills);</div><div class="line">    </div><div class="line">    <span class="comment">/**</span></div><div class="line">    * 响应是否有效</div><div class="line">    */</div><div class="line">    assert response != <span class="keyword">null</span>;</div><div class="line">    <span class="keyword">switch</span> (response.getCode()) &#123;</div><div class="line">        <span class="keyword">case</span> ResponseCode.SUCCESS: &#123;</div><div class="line">            RegisterBrokerResponseHeader responseHeader = </div><div class="line">                    (RegisterBrokerResponseHeader) response.decodeCommandCustomHeader(RegisterBrokerResponseHeader.class);</div><div class="line">            </div><div class="line">            RegisterBrokerResult result = <span class="keyword">new</span> RegisterBrokerResult();</div><div class="line">            <span class="comment">/**</span></div><div class="line">            * 处理broker为slave的场景</div><div class="line">            */</div><div class="line">            result.setMasterAddr(responseHeader.getMasterAddr());</div><div class="line">            result.setHaServerAddr(responseHeader.getHaServerAddr());</div><div class="line"></div><div class="line">            <span class="keyword">if</span> (response.getBody() != <span class="keyword">null</span>) &#123;</div><div class="line">                result.setKvTable(KVTable.decode(response.getBody(), KVTable.class));</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">return</span> result;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">default</span>:</div><div class="line">            <span class="keyword">break</span>;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> MQBrokerException(response.getCode(), response.getRemark());</div><div class="line">&#125;</div></pre></td></tr></table></figure><p></p><p>broker端注册broker主要是告诉namesrv自身的信息和broker所支持topic的信息，以便producer、consumer去namesrv查询broker的时候查询不到。</p><h2 id="namesrv端"><a href="#namesrv端" class="headerlink" title="namesrv端"></a>namesrv端</h2><p>在com.alibaba.rocketmq.namesrv.processor.DefaultRequestProcessor文件中处理请求信息。<br></p><figure class="highlight aspectj"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line">* broker注册请求</div><div class="line">*/</div><div class="line"><span class="keyword">case</span> RequestCode.REGISTER_BROKER:</div><div class="line">    Version brokerVersion = MQVersion.value2Version(request.getVersion());</div><div class="line">    <span class="comment">/**</span></div><div class="line">    * 3.0.11以后增加过滤服务,加以区分</div><div class="line">    */</div><div class="line">    <span class="keyword">if</span> (brokerVersion.ordinal() &gt;= MQVersion.Version.V3_0_11.ordinal()) &#123;</div><div class="line">        <span class="function"><span class="keyword">return</span> <span class="keyword">this</span>.<span class="title">registerBrokerWithFilterServer</span><span class="params">(ctx, request)</span></span>;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">else</span> &#123;</div><div class="line">        <span class="function"><span class="keyword">return</span> <span class="keyword">this</span>.<span class="title">registerBroker</span><span class="params">(ctx, request)</span></span>;</div><div class="line">    &#125;</div></pre></td></tr></table></figure><p></p><p>具体的处理逻辑在registerBrokerWithFilterServer中<br></p><figure class="highlight pony"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * @描述: 注册代理服务器</div><div class="line"> * @修改内容</div><div class="line"> * @参数：     </div><div class="line"> * @return RemotingCommand   </div><div class="line"> * @throws</div><div class="line"> */</div><div class="line">public <span class="type">RemotingCommand</span> registerBrokerWithFilterServer(<span class="type">ChannelHandlerContext</span> ctx, <span class="type">RemotingCommand</span> request)</div><div class="line">        throws <span class="type">RemotingCommandException</span> &#123;</div><div class="line">    final <span class="type">RemotingCommand</span> response = <span class="type">RemotingCommand</span>.createResponseCommand(<span class="type">RegisterBrokerResponseHeader</span>.<span class="keyword">class</span>);</div><div class="line">    final <span class="type">RegisterBrokerResponseHeader</span> responseHeader = (<span class="type">RegisterBrokerResponseHeader</span>) response.readCustomHeader();</div><div class="line">    final <span class="type">RegisterBrokerRequestHeader</span> requestHeader =</div><div class="line">            (<span class="type">RegisterBrokerRequestHeader</span>) request.decodeCommandCustomHeader(<span class="type">RegisterBrokerRequestHeader</span>.<span class="keyword">class</span>);</div><div class="line"></div><div class="line">    <span class="type">RegisterBrokerBody</span> registerBrokerBody = <span class="function"><span class="keyword">new</span> <span class="title">RegisterBrokerBody</span>();</span></div><div class="line"></div><div class="line">    <span class="title">if</span> (request.getBody() != <span class="title">null</span>) &#123;</div><div class="line">        <span class="title">registerBrokerBody</span> = <span class="title">RegisterBrokerBody</span>.<span class="title">decode</span>(request.getBody(), <span class="title">RegisterBrokerBody</span>.<span class="title">class</span>);</div><div class="line">    &#125; <span class="title">else</span> &#123;</div><div class="line">        <span class="title">registerBrokerBody</span>.<span class="title">getTopicConfigSerializeWrapper</span>().<span class="title">getDataVersion</span>().<span class="title">setCounter</span>(new <span class="type">AtomicLong</span>(<span class="number">0</span>));</div><div class="line">        <span class="title">registerBrokerBody</span>.<span class="title">getTopicConfigSerializeWrapper</span>().<span class="title">getDataVersion</span>().<span class="title">setTimestatmp</span>(<span class="number">0</span>);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">//在路由信息中注册broker和维护topic关系</span></div><div class="line">    <span class="title">RegisterBrokerResult</span> <span class="title">result</span> = <span class="title">this</span>.<span class="title">namesrvController</span>.<span class="title">getRouteInfoManager</span>().<span class="title">registerBroker</span>(//</div><div class="line">            requestHeader.getClusterName(),</div><div class="line">            <span class="title">requestHeader</span>.<span class="title">getBrokerAddr</span>(), </div><div class="line">            <span class="title">requestHeader</span>.<span class="title">getBrokerName</span>(), </div><div class="line">            <span class="title">requestHeader</span>.<span class="title">getBrokerId</span>(), </div><div class="line">            <span class="title">requestHeader</span>.<span class="title">getHaServerAddr</span>(),</div><div class="line">            <span class="title">registerBrokerBody</span>.<span class="title">getTopicConfigSerializeWrapper</span>(), </div><div class="line">            <span class="title">registerBrokerBody</span>.<span class="title">getFilterServerList</span>(),</div><div class="line">            <span class="title">ctx</span>.<span class="title">channel</span>()</div><div class="line">    );</div><div class="line"></div><div class="line">    <span class="title">responseHeader</span>.<span class="title">setHaServerAddr</span>(result.getHaServerAddr());</div><div class="line">    <span class="title">responseHeader</span>.<span class="title">setMasterAddr</span>(result.getMasterAddr());</div><div class="line"></div><div class="line"></div><div class="line">    <span class="title">byte</span>[] <span class="title">jsonValue</span> = <span class="title">this</span>.<span class="title">namesrvController</span>.<span class="title">getKvConfigManager</span>().<span class="title">getKVListByNamespace</span>(<span class="type">NamesrvUtil</span>.<span class="type">NAMESPACE_ORDER_TOPIC_CONFIG</span>);</div><div class="line">    <span class="title">response</span>.<span class="title">setBody</span>(jsonValue);</div><div class="line"></div><div class="line">    <span class="title">response</span>.<span class="title">setCode</span>(<span class="type">ResponseCode</span>.<span class="type">SUCCESS</span>);</div><div class="line">    <span class="title">response</span>.<span class="title">setRemark</span>(null);</div><div class="line">    <span class="title">return</span> <span class="title">response</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure><p></p><p>com.alibaba.rocketmq.namesrv.routeinfo.RouteInfoManager文件中实现了具体的注册逻辑</p><figure class="highlight processing"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div><div class="line">183</div><div class="line">184</div><div class="line">185</div><div class="line">186</div><div class="line">187</div><div class="line">188</div><div class="line">189</div><div class="line">190</div><div class="line">191</div><div class="line">192</div><div class="line">193</div><div class="line">194</div><div class="line">195</div><div class="line">196</div><div class="line">197</div><div class="line">198</div><div class="line">199</div><div class="line">200</div><div class="line">201</div><div class="line">202</div><div class="line">203</div><div class="line">204</div><div class="line">205</div><div class="line">206</div><div class="line">207</div><div class="line">208</div><div class="line">209</div><div class="line">210</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * @描述: 在namesrv上注册broker </div><div class="line"> * @修改内容</div><div class="line"> * @参数：@param clusterName  集群名称</div><div class="line"> * @参数：@param brokerAddr   broker地址</div><div class="line"> * @参数：@param brokerName   broker名称</div><div class="line"> * @参数：@param brokerId     brokerid  区分master和slave</div><div class="line"> * @参数：@param haServerAddr ha地址</div><div class="line"> * @参数：@param topicConfigWrapper  topic的配置信息</div><div class="line"> * @参数：@param filterServerList    filter地址</div><div class="line"> * @参数：@param channel             broker的socket通道</div><div class="line"> * @参数：@return  RegisterBrokerResult</div><div class="line"> * @throws</div><div class="line"> */</div><div class="line"><span class="keyword">public</span> RegisterBrokerResult registerBroker(<span class="comment">//</span></div><div class="line">                                           <span class="keyword">final</span> <span class="keyword">String</span> clusterName,<span class="comment">// 1</span></div><div class="line">                                           <span class="keyword">final</span> <span class="keyword">String</span> brokerAddr,<span class="comment">// 2</span></div><div class="line">                                           <span class="keyword">final</span> <span class="keyword">String</span> brokerName,<span class="comment">// 3</span></div><div class="line">                                           <span class="keyword">final</span> <span class="keyword">long</span> brokerId,<span class="comment">// 4</span></div><div class="line">                                           <span class="keyword">final</span> <span class="keyword">String</span> haServerAddr,<span class="comment">// 5</span></div><div class="line">                                           <span class="keyword">final</span> TopicConfigSerializeWrapper topicConfigWrapper,<span class="comment">// 6</span></div><div class="line">                                           <span class="keyword">final</span> List&lt;<span class="keyword">String</span>&gt; filterServerList, <span class="comment">// 7</span></div><div class="line">                                           <span class="keyword">final</span> Channel channel<span class="comment">// 8</span></div><div class="line">) </div><div class="line">&#123;</div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 注册结果</div><div class="line">     */</div><div class="line">    RegisterBrokerResult result = <span class="keyword">new</span> RegisterBrokerResult();</div><div class="line">    </div><div class="line">    <span class="keyword">try</span> &#123;</div><div class="line">        <span class="keyword">try</span> </div><div class="line">        &#123;   </div><div class="line">            <span class="comment">/**</span></div><div class="line">            *加锁</div><div class="line">            */</div><div class="line">            <span class="keyword">this</span>.lock.writeLock().lockInterruptibly();</div><div class="line"></div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 根据broker注册请求的集群名称获取对应的broker name集合 </div><div class="line">             */</div><div class="line">            Set&lt;<span class="keyword">String</span>&gt; brokerNames = <span class="keyword">this</span>.clusterAddrTable.<span class="built_in">get</span>(clusterName);</div><div class="line">            </div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 如果该集群对应的broker为空 </div><div class="line">             * 需要新建集群对应的broker集合存储对象</div><div class="line">             */</div><div class="line">            <span class="keyword">if</span> (<span class="keyword">null</span> == brokerNames) &#123;</div><div class="line">                brokerNames = <span class="keyword">new</span> HashSet&lt;<span class="keyword">String</span>&gt;();</div><div class="line">                <span class="comment">/**</span></div><div class="line">                 * 维护集群名称和集群broker集合对象的关系</div><div class="line">                 */</div><div class="line">                <span class="keyword">this</span>.clusterAddrTable.put(clusterName, brokerNames);</div><div class="line">            &#125;</div><div class="line">            </div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 把broker名称加到集群的broker集合中去</div><div class="line">             */</div><div class="line">            brokerNames.<span class="built_in">add</span>(brokerName);</div><div class="line"></div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 默认不是第一次注册</div><div class="line">             */</div><div class="line">            <span class="built_in">boolean</span> registerFirst = <span class="keyword">false</span>;</div><div class="line"></div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 获取broker的信息</div><div class="line">             */</div><div class="line">            BrokerData brokerData = <span class="keyword">this</span>.brokerAddrTable.<span class="built_in">get</span>(brokerName);</div><div class="line">            </div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 如果没有查到broker信息 则创建</div><div class="line">             */</div><div class="line">            <span class="keyword">if</span> (<span class="keyword">null</span> == brokerData) </div><div class="line">            &#123;</div><div class="line">                <span class="comment">/**</span></div><div class="line">                 * 是第一次注册</div><div class="line">                 */</div><div class="line">                registerFirst = <span class="keyword">true</span>;</div><div class="line">                brokerData = <span class="keyword">new</span> BrokerData();</div><div class="line">                brokerData.setBrokerName(brokerName);</div><div class="line">                <span class="comment">/**</span></div><div class="line">                 * 该broker对应的地址</div><div class="line">                 */</div><div class="line">                <span class="keyword">HashMap</span>&lt;Long, <span class="keyword">String</span>&gt; brokerAddrs = <span class="keyword">new</span> <span class="keyword">HashMap</span>&lt;Long, <span class="keyword">String</span>&gt;();</div><div class="line">                brokerData.setBrokerAddrs(brokerAddrs);</div><div class="line"></div><div class="line">                <span class="comment">/**</span></div><div class="line">                 * 维护broker地址表格数据</div><div class="line">                 */</div><div class="line">                <span class="keyword">this</span>.brokerAddrTable.put(brokerName, brokerData);</div><div class="line">            &#125;</div><div class="line">            </div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 把broker的id和地址加入到broker地址集合中去</div><div class="line">             * 通过brokerid区分主-从 broker</div><div class="line">             */</div><div class="line">            <span class="keyword">String</span> oldAddr = brokerData.getBrokerAddrs().put(brokerId, brokerAddr);</div><div class="line">            </div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 再次判定该broker是否是第一次创建</div><div class="line">             */</div><div class="line">            registerFirst = registerFirst || (<span class="keyword">null</span> == oldAddr);</div><div class="line"></div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 如果topic配置存在 </div><div class="line">             * 同时该broker是主broker的话</div><div class="line">             */</div><div class="line">            <span class="keyword">if</span> (<span class="keyword">null</span> != topicConfigWrapper <span class="comment">//</span></div><div class="line">                    &amp;&amp; MixAll.MASTER_ID == brokerId) </div><div class="line">            &#123;</div><div class="line">                <span class="comment">/**</span></div><div class="line">                 * 如果topic的配置有变化</div><div class="line">                 * 或者是第一次注册broker的话</div><div class="line">                 * 需要创建或者更新broker对应的队列信息</div><div class="line">                 */</div><div class="line">                <span class="keyword">if</span> (<span class="keyword">this</span>.isBrokerTopicConfigChanged(brokerAddr, topicConfigWrapper.getDataVersion())<span class="comment">//</span></div><div class="line">                        || registerFirst) </div><div class="line">                &#123;</div><div class="line">                    ConcurrentHashMap&lt;<span class="keyword">String</span>, TopicConfig&gt; tcTable = topicConfigWrapper.getTopicConfigTable();</div><div class="line">                    <span class="keyword">if</span> (tcTable != <span class="keyword">null</span>) &#123;</div><div class="line">                        <span class="keyword">for</span>(Map.Entry&lt;<span class="keyword">String</span>,TopicConfig&gt; entry: tcTable.entrySet())</div><div class="line">                        &#123;</div><div class="line">                            <span class="comment">/**</span></div><div class="line">                             * 创建、更新队列配置数据</div><div class="line">                             */</div><div class="line">                            <span class="keyword">this</span>.createAndUpdateQueueData(brokerName, entry.getValue());</div><div class="line">                        &#125;</div><div class="line">                    &#125;</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line"></div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 把当前注册的broker放入到broker有效集合</div><div class="line">             */</div><div class="line">            BrokerLiveInfo prevBrokerLiveInfo = <span class="keyword">this</span>.brokerLiveTable.put(brokerAddr, <span class="comment">//</span></div><div class="line">                    <span class="keyword">new</span> BrokerLiveInfo(<span class="comment">//</span></div><div class="line">                            System.currentTimeMillis(), <span class="comment">//</span></div><div class="line">                            topicConfigWrapper.getDataVersion(),<span class="comment">//</span></div><div class="line">                            channel, <span class="comment">//</span></div><div class="line">                            haServerAddr));</div><div class="line">            </div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 第一次加入</div><div class="line">             */</div><div class="line">            <span class="keyword">if</span> (<span class="keyword">null</span> == prevBrokerLiveInfo) &#123;</div><div class="line">                <span class="built_in">log</span>.info(<span class="string">"new broker registerd, &#123;&#125; HAServer: &#123;&#125;"</span>, brokerAddr, haServerAddr);</div><div class="line">            &#125;</div><div class="line"></div><div class="line">            <span class="comment">/**</span></div><div class="line">             * 如果过滤服务器对象不为null</div><div class="line">             */</div><div class="line">            <span class="keyword">if</span> (filterServerList != <span class="keyword">null</span>) </div><div class="line">            &#123;</div><div class="line">                <span class="keyword">if</span> (filterServerList.isEmpty()) </div><div class="line">                &#123;</div><div class="line">                    <span class="comment">/**</span></div><div class="line">                     * 如果是空的,说明需要删除</div><div class="line">                     */</div><div class="line">                    <span class="keyword">this</span>.filterServerTable.remove(brokerAddr);</div><div class="line">                &#125; </div><div class="line">                <span class="keyword">else</span> </div><div class="line">                &#123;</div><div class="line">                    <span class="comment">/**</span></div><div class="line">                     * 需要添加或者更新</div><div class="line">                     */</div><div class="line">                    <span class="keyword">this</span>.filterServerTable.put(brokerAddr, filterServerList);</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line"></div><div class="line"></div><div class="line">            <span class="comment">/**</span></div><div class="line">             * slave的broker的处理</div><div class="line">             */</div><div class="line">            <span class="keyword">if</span> (MixAll.MASTER_ID != brokerId) </div><div class="line">            &#123;</div><div class="line">                <span class="comment">/**</span></div><div class="line">                 * 获取master broker地址</div><div class="line">                 */</div><div class="line">                <span class="keyword">String</span> masterAddr = brokerData.getBrokerAddrs().<span class="built_in">get</span>(MixAll.MASTER_ID);</div><div class="line">                <span class="keyword">if</span> (masterAddr != <span class="keyword">null</span>) </div><div class="line">                &#123;</div><div class="line">                    <span class="comment">/**</span></div><div class="line">                     * 如果当前master的broker存在的话</div><div class="line">                     * 把master的地址和ha地址发送给slave broker</div><div class="line">                     */</div><div class="line">                    BrokerLiveInfo brokerLiveInfo = <span class="keyword">this</span>.brokerLiveTable.<span class="built_in">get</span>(masterAddr);</div><div class="line">                    <span class="keyword">if</span> (brokerLiveInfo != <span class="keyword">null</span>) &#123;</div><div class="line">                        result.setHaServerAddr(brokerLiveInfo.getHaServerAddr());</div><div class="line">                        result.setMasterAddr(masterAddr);</div><div class="line">                    &#125;</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">        &#125; <span class="keyword">finally</span> &#123;</div><div class="line">            <span class="keyword">this</span>.lock.writeLock().unlock();</div><div class="line">        &#125;</div><div class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</div><div class="line">        <span class="built_in">log</span>.error(<span class="string">"registerBroker Exception"</span>, e);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">return</span> result;</div><div class="line">&#125;</div><div class="line"><span class="keyword">private</span> <span class="built_in">boolean</span> isBrokerTopicConfigChanged(<span class="keyword">final</span> <span class="keyword">String</span> brokerAddr, <span class="keyword">final</span> DataVersion dataVersion) &#123;</div><div class="line">    BrokerLiveInfo prev = <span class="keyword">this</span>.brokerLiveTable.<span class="built_in">get</span>(brokerAddr);</div><div class="line">    <span class="keyword">if</span> (<span class="keyword">null</span> == prev || !prev.getDataVersion().equals(dataVersion)) &#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure><p>服务端处理broker注册请求逻辑就完成了。</p></div></div><div class="copyright"><p><span>本文标题:</span><a href="/rocketmq/2016/11/13/rocketmq-broker-synctopic2namesrv.html">rocketmq中broker启动同步topic到namesrv过程</a></p><p><span>文章作者:</span><a href="/" title="访问 lehoon 的个人博客">lehoon</a></p><p><span>发布时间:</span>2016年11月13日 - 20时43分</p><p><span>最后更新:</span>2016年11月24日 - 15时52分</p><p><span>原始链接:</span><a class="post-url" href="/rocketmq/2016/11/13/rocketmq-broker-synctopic2namesrv.html" title="rocketmq中broker启动同步topic到namesrv过程">http://blog.lehoon.cn/rocketmq/2016/11/13/rocketmq-broker-synctopic2namesrv.html</a><span class="copy-path" data-clipboard-text="原文: http://blog.lehoon.cn/rocketmq/2016/11/13/rocketmq-broker-synctopic2namesrv.html　　作者: lehoon" title="点击复制文章链接"><i class="fa fa-clipboard"></i></span><script src="/js/clipboard.min.js"></script><script>var clipboard=new Clipboard(".copy-path")</script></p><p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" title="中国大陆 (CC BY-NC-SA 3.0 CN)" target="_blank">"署名-非商用-相同方式共享 3.0"</a> 转载请保留原文链接及作者。</p></div><nav id="article-nav"><a href="/rocketmq/2016/11/25/rocketmq-net-port.html" id="article-nav-newer" class="article-nav-link-wrap"><strong class="article-nav-caption">&lt;</strong><div class="article-nav-title">rocketmq服务中的端口号</div></a><a href="/orther/2016/11/10/java-error-note.html" id="article-nav-older" class="article-nav-link-wrap"><div class="article-nav-title">java常见错误</div><strong class="article-nav-caption">&gt;</strong></a></nav></article><div id="toc" class="toc-article"><strong class="toc-title">文章目录</strong><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#broker端"><span class="toc-number">1.</span> <span class="toc-text">broker端</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#topic的获取"><span class="toc-number">1.1.</span> <span class="toc-text">topic的获取</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#同步到namesrv"><span class="toc-number">1.2.</span> <span class="toc-text">同步到namesrv</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#namesrv端"><span class="toc-number">2.</span> <span class="toc-text">namesrv端</span></a></li></ol></div><input type="button" id="tocButton" value="隐藏目录" title="点击按钮隐藏或者显示文章目录"><script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script><script>var valueHide="隐藏目录",valueShow="显示目录";$(".left-col").is(":hidden")&&$("#tocButton").attr("value",valueShow),$("#tocButton").click(function(){$("#toc").is(":hidden")?($("#tocButton").attr("value",valueHide),$("#toc").slideDown(320)):($("#tocButton").attr("value",valueShow),$("#toc").slideUp(350))}),$(".toc").length<1&&$("#toc, #tocButton").hide()</script><div class="scroll" id="post-nav-button"><a href="/rocketmq/2016/11/25/rocketmq-net-port.html" title="上一篇: rocketmq服务中的端口号"><i class="fa fa-angle-left"></i></a><a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a><a href="/orther/2016/11/10/java-error-note.html" title="下一篇: java常见错误"><i class="fa fa-angle-right"></i></a></div><ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/orther/2017/02/22/source-insight4-crack.html">source insight4安装使用</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2017/02/21/rocketmq-topic-delete.html">rocketmq删除topic</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2017/02/21/rocketmq-message-store.html">rocketmq消息存储</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2017/02/20/idempotent-define.html">幂等介绍</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2017/02/20/github-sync-fork-upstream.html">github上fork项目源同步</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2017/02/16/intellij-idea-2016.html">intellij-idea-2016下载安装</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2017/01/24/bubiao-protocol.html">部标808协议文件</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2017/01/24/life-secret.html">生活小秘方</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2017/01/10/mysql-odbc-driver-error.html">无法加载mysql odbc 5.3 unicode driver</a></li><li class="post-list-item"><a class="post-list-link" href="/rocketmq/2016/11/25/rocketmq-net-port.html">rocketmq服务中的端口号</a></li><li class="post-list-item"><a class="post-list-link" href="/rocketmq/2016/11/13/rocketmq-broker-synctopic2namesrv.html">rocketmq中broker启动同步topic到namesrv过程</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/11/10/java-error-note.html">java常见错误</a></li><li class="post-list-item"><a class="post-list-link" href="/rocketmq/2016/11/09/rocketmq-install-note.html">rocketmq安装记录</a></li><li class="post-list-item"><a class="post-list-link" href="/rocketmq/2016/11/09/rocketmq-docs.html">Rocketmq文档</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/10/28/game-develop-skill.html">游戏开发要点</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/10/14/oracle-error-note.html">oracle错误记录</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/10/11/oracle-materialized-view.html">oracle物化视图</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/10/09/centos-oracle11gr2-install.html">Centos7安装oracle11gr2</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/10/08/gdb-miss-debuginfo.html">gdb-miss-debuginfo</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/09/29/linux-io-schedule.html">Linux IO调度算法</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/09/27/linux-c-func.html">Linux下C函数定义</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/09/26/tcpdump.html">tcpdump使用文档</a></li><li class="post-list-item"><a class="post-list-link" href="/编程/2016/09/20/eim.html">eim</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/09/16/linux-strace.html">linux-strace使用介绍</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/09/16/linux-brk-sbrk.html">brk,sbrk--改变数据段长度</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/09/07/centos-note.html">Centos记录</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/09/05/raid.html">raid磁盘阵列介绍</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/09/02/nginx-load-balance.html">nginx负载均衡各种场景下的应用</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/09/01/usb-centos-error.html">U盘安装centos7，启动报错</a></li><li class="post-list-item"><a class="post-list-link" href="/frontend/2016/09/01/js-generate-uuid.html">JavaScript生成全局唯一id的方法</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/08/29/notepad.html">随笔</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/08/22/kafka-window.html">kafka在window下部署</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/08/19/makefile.html">Makefile学习</a></li><li class="post-list-item"><a class="post-list-link" href="/frontend/2016/08/16/http-etag-last-midified.html">HTTP缓存ETAG和Last-Modified</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/08/16/ip-catagory.html">ip地址分类</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/08/09/android-connection-session.html">android非浏览器应用程序与服务器会话保持实现</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/07/28/memcache-memcached-diff.html">memcache与memcached区别</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/07/19/centos-lvs.html">CentOS 7.0下安装部署LVS</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/07/19/awk.html">awk学习</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/07/11/epoll.html">Linux epoll学习</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/07/04/golang-deamon.html">go守护进程实现方式</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/07/04/tcp-load-balancing.html">tcp连接负载均衡</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/07/04/tcp-rst.html">tcp出现rst情况</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2016/05/26/linux-tcp-optimization.html">Linux下tcp的优化</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/05/08/oracle-merge-into.html">oracle中merge into语法注意点</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2016/02/05/window-batch.html">Window批处理记录</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2015/10/11/kesankaoshi.html">机动车驾驶科目三操作要领</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2015/09/28/window-service-program.html">window服务编程</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2015/09/21/assembly-instruction.html">汇编指令集</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2015/09/15/bool-BOOL.html">bool和BOOL的区别</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2015/08/20/ssh-limit.html">ssh限制ip远程登录</a></li><li class="post-list-item"><a class="post-list-link" href="/orther/2015/08/18/ue-regex.html">ultraedit正则表达式使用</a></li><li class="post-list-item"><a class="post-list-link" href="/backend/2015/05/07/occi.html">c++使用occi连接oracle</a></li><li class="post-list-item"><a class="post-list-link" href="/frontend/2015/03/06/gulp.html">gulp 提高页面加载速度</a></li></ul><script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script><script>$(".post-list").addClass("toc-article"),$(".post-list-item a").attr("target","_blank"),$("#post-nav-button > a:nth-child(2)").click(function(){$(".fa-bars, .fa-times").toggle(),$(".post-list").toggle(300),$(".toc").length>0&&$("#toc, #tocButton").toggle(200,function(){$(".switch-area").is(":visible")&&$("#tocButton").attr("value",valueHide)})})</script><script></script></div><footer id="footer"><div class="outer"><div id="footer-info"><div class="footer-left">&copy; 2017 lehoon</div><div class="footer-right"><a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/luuman/hexo-theme-spfk" target="_blank">spfk</a> by luuman</div></div></div></footer></div><script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js"></script><script src="http://static.lehoon.cn/js/main.js"></script><script>$(document).ready(function(){})</script><div class="scroll" id="scroll"><a href="#"><i class="fa fa-arrow-up"></i></a><a href="#comments"><i class="fa fa-comments-o"></i></a><a href="#footer"><i class="fa fa-arrow-down"></i></a></div><script>$(document).ready(function(){$("#comments").length<1&&$("#scroll > a:nth-child(2)").hide()})</script><script language="javascript">$(function(){$("a[title]").each(function(){var t=$(this),e=t.attr("title");void 0!=e&&""!=e&&t.data("title",e).removeAttr("title").hover(function(){var i=t.offset();$('<div id="anchortitlecontainer"></div>').appendTo($("body")).html(e).css({top:i.top-t.outerHeight()-15,left:i.left+t.outerWidth()/2+1}).fadeIn(function(){var t=$(this);setTimeout(function(){t.remove()},800*t.text().length)})},function(){$("#anchortitlecontainer").remove()})})})</script></div></body></html>